<template>
  <basic-container>
    <avue-crud :option="option"
               :data="data"
               ref="crud"
               v-model="form"
               :table-loading="loading"
               :permission="permissionList"
               :page="page"
               @refresh-change="refreshChange"
               @search-change="searchChange"
               @search-reset="searchReset"
               @current-change="currentChange"
               @size-change="sizeChange"
               @on-load="onLoad">
<!--      <template slot-scope="{}"-->
<!--                slot="menuLeft">-->
<!--        <el-button size="mini"-->
<!--                   type="default"-->
<!--                   icon="el-icon-delete"-->
<!--                   @click="delAll" v-has="'/mall-cloud-system/loginLog/delLoginLog'">清空全部</el-button>-->
<!--      </template>-->
    </avue-crud>
  </basic-container>
</template>

<script>
import {
  getList,
  delAll
} from "@/api/admin/loginLog";
import { mapGetters } from "vuex";

export default {
  data () {
    return {
      form: {},
      query: {},
      loading: true,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      option: {
        size: 'mini',
        tip: false,
        border: true,
        index: true,
        viewBtn: false,
        addBtn: false,
        delBtn: false,
        editBtn: false,
        height: 'auto',
        // calcHeight: 380,
        dialogType: 'dialog',
        rowKey: 'loginLogId',
        menu: false,
	    align:'center',
	    searchMenuSpan:6,
        column: [
          {
            label: "登录名称",
            prop: "logName",
          //  search: true,
            fixed: true,
          },
          {
            label: "用户名称",
            prop: "userName"
          },
          {
            label: "时间",
            prop: "createTime"
          },
          {
            label: "具体信息",
            prop: "regularMessage",
            overHidden: true
          },
          {
            label: "ip",
            prop: "ipAddress",
          }
        ]
      },
      data: []
    };
  },
  computed: {
    ...mapGetters(["permission", 'userInfo']),
    permissionList () {
      return {

      };
    },
  },
  methods: {
    delAll () {
      this.$confirm("是否清空全部日志", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          return delAll().then(()=>{
              this.onLoad(this.page);
          })
        })
    },
    searchReset () {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange (params,done) {
      this.query = params;
      this.onLoad(this.page, params,done);
    },
    currentChange (currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange (pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange () {
      this.onLoad(this.page);
    },
    onLoad (page, params = {},done) {
      this.loading = true;
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
        if(done){
          done();
        }
        this.loading = false;
        const data = res.data;
        this.page.total = data.count;
        this.data = data.data
      });
    }
  }
};
</script>

<style scoped>
</style>
